import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param a int整型二维数组 
     * @return long长整型
     */

    long ret = 0;

    public long queryMaxSum (int[][] a) {
        // write code here
        
        int n = a[0].length;
        int[][] vis = new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                vis[i][j] = 1;

                for (int k = 0; k < 4; k++) {
                    int xx = i + dist[k][0];
                    int yy = j + dist[k][1];

                    if (xx >= 0 && xx < 2 && yy >= 0 && yy < vis[0].length) {
                        if (vis[xx][yy] == 0) {
                            vis[xx][yy] = 2;
                        }
                    }
                }

                dfs (a, i, j, vis, a[i][j]);
                vis[i][j] = 0;

                for (int k = 0; k < 4; k++) {
                    int xx = i + dist[k][0];
                    int yy = j + dist[k][1];

                    if (xx >= 0 && xx < 2 && yy >= 0 && yy < vis[0].length) {
                        if (vis[xx][yy] == 2) {
                            vis[xx][yy] = 0;
                        }
                    }
                }
            }
        }

        return ret;
    }

    int[][] dist = {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}};

    public void dfs (int[][] a, int row, int col, int[][] vis, int sum) {
        ret = Math.max(ret, sum);
        System.out.println(sum);

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < vis[i].length; j++) {
                if ((i == row && j == col - 1)
                || (i == row && j == col + 1)
                || (i == row - 1 && j == col)
                || (i == row + 1 && j == col)
                || (i == row || j == col)) {
                    continue;
                }
                else if (vis[i][j] == 0){
                    vis[i][j] = 1;

                    for (int k = 0; k < 4; k++) {
                        int xx = i + dist[k][0];
                        int yy = j + dist[k][1];

                        if (xx >= 0 && xx < 2 && yy >= 0 && yy < vis[0].length) {
                            if (vis[xx][yy] == 0) {
                                vis[xx][yy] = 2;
                            }
                        }
                    }

                    dfs (a, i, j, vis, sum + a[i][j]);
                    vis[i][j] = 0;

                    for (int k = 0; k < 4; k++) {
                        int xx = i + dist[k][0];
                        int yy = j + dist[k][1];

                        if (xx >= 0 && xx < 2 && yy >= 0 && yy < vis[0].length) {
                            if (vis[xx][yy] == 2) {
                                vis[xx][yy] = 0;
                            }
                        }
                    }
                }

            }
        }
    }
}